import React, { memo } from "react";
import { useState } from "react";
import {add} from "../store/goods"
import { useDispatch } from "react-redux";
const Search = memo(() => {
  const [value, setValue] = useState("");
  const dispatch = useDispatch()
  return (
    <div className="search">
      <input
        type="text"
        placeholder="请输入任务名称"
        value={value}
        onChange={(e) => setValue(e.target.value)}
      />
      <button onClick={()=>{
        if(value!==""){
          dispatch(add(value))
          setValue('')
        }else {
          alert("输入内容不能为空")
        }
      }}>点击添加任务</button>
    </div>
  );
});

export default Search;
